package com.ouc.controller;

import com.ouc.common.Result;
import com.ouc.entity.Line;
import com.ouc.entity.Material;
import com.ouc.entity.Shape;
import com.ouc.entity.ShapeType;
import com.ouc.service.LineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Name: ShapeCommonController
 * @Description:
 * @Author: Mr.Tong
 */
@RestController
@RequestMapping("/common")
@CrossOrigin
@Api(tags = "所有形状公共接口", description = "提供所有形状公共的接口信息")
public class ShapeCommonController {

    @Autowired
    private LineService lineService;

    @Autowired
    private ShapeType shapeType;

    @Autowired
    private Material material;


    /**
     * @Description: 获取所有的形状类型
     * @Author: Mr.Tong
     */
    @ApiOperation("获取所有形状类型")
    @GetMapping("/getallshapetype")
    public Result getAllShapetype() {
        return Result.ok()
                .data("type", shapeType.getType())
                .data("code", shapeType.getCode())
                .data("unitAreaPrice", shapeType.getUnitAreaPrice());
    }


    /**
     * @Description: 得到所有的材料类型
     * @Author: Mr.Tong
     */
    @ApiOperation("获取所有的材料信息")
    @GetMapping("/getallmaterial")
    public Result getAllMatrial() {
        return Result.ok()
                .data("type", material.getType())
                .data("code", material.getCode());
    }

    /**
     * @Description: 根据材料类型获得口径和价格
     * @Author: Mr.Tong
     */
    @ApiOperation("根据材料类型获得口径和价格")
    @GetMapping("/getcaliberbymaterial")
    public Result getCaliberByMaterial(String materialType) {
        List<Line> lineByMaterialType = lineService.getLineByMaterialType(materialType);
        return Result.ok()
                .data("line", lineByMaterialType);
    }

}
